#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

void solve() {
	int n, x, y, a, b;
	cin >> n >> x >> y >> a >> b;
	if (n < y || b < x) {
		cout << -1 << endl; return;
	}
	int q = n / y, w = a / x, e = b / x;
	if (w >= e) e = w - 1;
	cout << min(q, w + e) << endl;
}

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T; cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}